package logic

import (
	"context"
	"src/srcclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderCreateLogic {
	return &OrderCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderCreateLogic) OrderCreate(req *types.OrderCreateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	OrderGood, err := l.svcCtx.SrcRpc.OrderGood(l.ctx, &srcclient.OrderGoodRequest{
		Title:       req.Title,
		Price:       int64(req.Price),
		Stock:       int64(req.Stock),
		Status:      req.Status,
		LikeCollect: int64(req.LikeCollect),
		Id:          int64(req.Id),
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: "200",
		Msg:  "订单生成成功",
		Data: OrderGood,
	}, nil
}
